import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App.vue'
import store from './store'
import router from './router'

import * as directives from './directives/index'
import * as filters from '../src/filters'
import '@/icons' // icon
import '@/permission' // permission control
import Component from '@/components'
import checkPermission from './mixin/checkPermission'
import i18n from './lang/index'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */

// set ElementUI lang to EN
Vue.use(ElementUI, {
  // element本身支持I18n的处理
  // 此时i18n就会根据当前的locale属性找对应的显示内容
  i18n: (key, value) => i18n.t(key) // t方法 回去对应的语言包里寻找对应的内容
  // 改变 locale的值就能改变对应的当前语言
})
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
console.log(Object.keys(directives))
// console.log(Object.keys(directives)) // 得到一个自定义里面的数组
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
  console.log(directives[key])
})
// console.log(Object.keys(filters)) // 所有过滤器数组集合
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]) // 注册注册自定义过滤器
})

Vue.use(Component) // 注册自己的插件
// 全局混入检查对象
Vue.mixin(checkPermission) // 表示所有组件都拥有了检查的方法

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
